/*
 *  Copyright (C) 2011 JiangHongTiao <jjurco.sk_gmail.com>
 * 
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 * 
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 * 
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package sk.lieskove301.jianghongtiao.liaad.prisoner.statistics;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import sk.lieskove301.jianghongtiao.liaad.prisoner.agent.Agent;
import sk.lieskove301.jianghongtiao.liaad.prisoner.gene.GeneticInfo;

/**
 * Date of create: May 15, 2011
 *
 * @author JiangHongTiao <jjurco.sk_gmail.com>
 * @version 2011.0515
 */
public class CommonStatistics {
    
    public static Map<GeneticInfo, List<Agent>> groupAgentsByGene(List<Agent> agents){
        Map<GeneticInfo, List<Agent>> result = new TreeMap<GeneticInfo, List<Agent>>();
        for (Iterator<Agent> it = agents.iterator(); it.hasNext();) {
            Agent agent = it.next();
            if(result.containsKey(agent.getGene())){
                List<Agent> lst = result.get(agent.getGene());
                lst.add(agent);
                result.put(agent.getGene(), lst);
            } else {
                List<Agent> lst = new LinkedList<Agent>();
                lst.add(agent);
                result.put(agent.getGene(), lst);
            }
        }
        return result;
    }

    public static void writeAgentsByGene(List<Agent> agents){
        Map<GeneticInfo, List<Agent>> result = groupAgentsByGene(agents);

        for (Iterator<GeneticInfo> it = result.keySet().iterator(); it.hasNext();) {
            GeneticInfo geneEnums = it.next();
            System.out.println("Gene: " + geneEnums + " Count: " + result.get(geneEnums).size());
        }
    }

    public static void writeAgents(List<Agent> agents){
        for (Iterator<Agent> it = agents.iterator(); it.hasNext();) {
            Agent agent = it.next();
            System.out.println("Gene: " + agent.getGene());
        }
    }

    public static void makeScoreGraph(List<Agent> agents){
        
    }
}
